	var isIE = false;
	var isMozilla = false;
	var numEtapa = 0;
	var pagina = "inicial";
	
	function posicionaTitulo(winW, winH) {

	}

	function checkVersion () {
		var versionOK = true;
		var elem = document.createElement('canvas');
		return !!(elem.getContext && elem.getContext('2d'));
		/*
		var cvsEl, ctx;
		if (!window.WebGLRenderingContext) {
			versionOK = false;
			alert("sem webgl");
		    //window.location = "http://get.webgl.org";
		} else {
		    cvsEl = document.createElement("canvas");
		    ctx = cvsEl.getContext("webgl") || cvsEl.getContext("experimental-webgl");

		    if (!ctx) {
		    	alert("sem context");
		        // Browser supports WebGL, but cannot create the context
		    	versionOK = false;
		    }
		}
		*/
		return versionOK;
	}
	
	function resize() {
		//alert("resize...");
    	var winW = 630, winH = 460;

		if (parseInt(navigator.appVersion) > 3) {
			//alert("navigator.appName = " + navigator.appName);
			//alert("navigator.version = " + navigator.appVersion);
			//alert("navigator.appCodeName = " + navigator.appCodeName);
			var D = document;
			winH = Math.max(
			        	Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
			        	Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
			        	Math.max(D.body.clientHeight, D.documentElement.clientHeight)
			        );
			
			winW = Math.max(
		        	Math.max(D.body.scrollWidth, D.documentElement.scrollWidth),
		        	Math.max(D.body.offsetWidth, D.documentElement.offsetWidth),
		        	Math.max(D.body.clientWidth, D.documentElement.clientWidth)
		        );
		
			/*
			if (navigator.appName=="Netscape") {
				isMozilla = true;
				winW = window.innerWidth;
  				winH = window.innerHeight;
			}
			if (navigator.appName.indexOf("Microsoft") != -1) {
				isIE = true;
				winW = document.body.offsetWidth;
				winH = document.body.offsetHeight;
			}
			*/
		}

		var minimoTotalW = 850;
		var minimoTotalH = 500;
		var heightInsufiente = false;

		minimoTotalW = 1200;
		minimoTotalH = 600;
		if (pagina == "detalhecomparacao") {
			minimoTotalH = 800;
		}

		if (minimoTotalW > winW) { //cliente esta utilizando resolucao grande. retirar as margens
			winW = minimoTotalW;
		}
		if (minimoTotalH > winH) { //cliente esta utilizando resolucao grande. retirar as margens
			winH = minimoTotalH;
			heightInsufiente = true;
		}

		//alert("WinW = " + winW);
		//alert("WinH = " + winH);

		//alert("mybody = " + document.getElementById("mybody").offsetHeight);

		if (document.getElementById("divHeader")) {
			document.getElementById("divHeader").style.width = ((winW - (heightInsufiente?20:0)) + "px");
		}

		if (document.getElementById("divFooter")) {
			document.getElementById("divFooter").style.width = ((winW - (heightInsufiente?20:0)) + "px");
			if (document.getElementById("divBackGroundFundo")) {
				document.getElementById("divBackGroundFundo").style.width = ((winW - (heightInsufiente?20:0)) + "px");
			}
			//alert("document divFooter width = " + document.getElementById("divFooter").style.width);
		}

		//document.getElementById("mybody").style.width = (winW + "px");
		document.getElementById("mybody").style.height = (winH + "px");
		var calc = winH - document.getElementById("divHeader").offsetHeight;
		if (document.getElementById("divAbaixoTitulo")) {
			var calc = winH;
			if (document.getElementById("divHeader")) {
				calc -= document.getElementById("divHeader").offsetHeight;
			}
			if (document.getElementById("divFooter")) {
				calc -= document.getElementById("divFooter").offsetHeight;
			}
			document.getElementById("divAbaixoTitulo").style.height = calc + "px";
			document.getElementById("divAbaixoTitulo").style.width = ((winW - (heightInsufiente?20:0)) + "px");
		}

		if (document.getElementById("subDivBtnIniciais")) {
			document.getElementById("subDivBtnIniciais").style.width = ((winW - 451) + "px");
		}
		
		//alert("pagina = " + pagina);
		if (pagina == "principal") {
			//alert("redimensionando divconteudo...");
			document.getElementById("divConteudo").style.top = "165px"; //parseInt(document.getElementById("divBtnIniciais").style.height);
			//document.getElementById("divConteudo").style.left = "201px";
			document.getElementById("divConteudo").style.width = ((winW - 201 - (heightInsufiente?20:0)) + "px");
			//document.getElementById("divConteudo").style.height = ((calc - 170) + "px");
			document.getElementById("divComparacao").style.height = ((calc - 205) + "px");
			//document.getElementById("subDivBtnIniciais").style.width = ((winW - 451) + "px");
			//alert("pagina principal = " + pagina + ", width abaixo titulo=" + document.getElementById("divAbaixoTitulo").style.width);

		} else if (pagina == "comparacao2") {
			//document.getElementById("divConteudo").style.top = "0px";
			//document.getElementById("divConteudo").style.left = "0px";
			//document.getElementById("divConteudo").style.width = (winW + "px");
			document.getElementById("divMain").style.height = (calc + "px");
			//alert("resize comparacao2 ok...");
		} else if (pagina == "comparacaoMulti") {
			//document.getElementById("divProdutoRotacao").style.width = (winW - 600 - 230) + "px";
			document.getElementById("divprodrot").style.height = 425 + "px";
			
			//alert("resize comparacaoMulti");
		} else if (pagina == "testegame") {
			document.getElementById("divConteudo").style.top = "0px";
			document.getElementById("divConteudo").style.left = "0px";
			alert("resize testegame");
		} else if (pagina == "detalhecomparacao") {
			document.getElementById("divConteudo").style.top = "0px";
			document.getElementById("divConteudo").style.left = "0px";
			document.getElementById("divComparacao").style.height = (winH + "px");
			//alert("subplacar left:" + document.getElementById("divSubPlacar").offsetLeft);
			if (document.getElementById("divCompartilhar") && document.getElementById("divSubPlacar")) {
				var widthPlacar = parseInt(document.getElementById("divSubPlacar").offsetWidth);
				//alert("widthPlacar = " + widthPlacar);
				//var widthComp = parseInt(document.getElementById("divCompartilhar").offsetWidth);
				var widthComp = 78;
				//alert("widthComp = " + widthComp);
				document.getElementById("divCompartilhar").style.left = (parseInt(document.getElementById("divSubPlacar").offsetLeft) + widthPlacar - widthComp) + "px";
			}

			if (document.getElementById("tituloPergunta") && document.getElementById("divLinkBlog")) {
				var widthTitulo = parseInt(document.getElementById("tituloPergunta").offsetWidth);
				var leftTitulo = parseInt(document.getElementById("tituloPergunta").offsetLeft);
				//alert("width titulo pergunta = " + widthTitulo + ", left: " + leftTitulo);

				document.getElementById("divLinkBlog").style.left = leftTitulo + "px";
			}
			//alert("resize detalhecomparacao ok");
		} else if (pagina == "produto") {
			document.getElementById("divConteudo").style.top = "165px";
			//document.getElementById("divConteudo").style.left = "201px";
			document.getElementById("divConteudo").style.width = ((winW - 201) + "px");
			//document.getElementById("divConteudo").style.height = ((winH - 205) + "px");
			document.getElementById("divProdutos").style.height = ((calc - 205) + "px");

		} else if (pagina == "produtoCategoria") {
			document.getElementById("divConteudo").style.top = "165px";
			//document.getElementById("divConteudo").style.left = "201px";
			document.getElementById("divConteudo").style.width = ((winW - 201) + "px");
			//document.getElementById("divConteudo").style.height = ((winH - 205) + "px");
			document.getElementById("divCategoria").style.height = ((calc - 205) + "px");
			//document.getElementById("subDivBtnIniciais").style.width = ((winW - 451) + "px");

		} else if (pagina == "editar") {
			document.getElementById("divCadastro").style.width = ((winW - 201) + "px");
			document.getElementById("divCadastro").style.height = "100%";
			document.getElementById("divConteudo").style.top = "0px";
			//document.getElementById("subDivBtnIniciais").style.width = ((winW - 451) + "px");
			//alert("resize editar");
		} else if (pagina == "minilink") {
			document.getElementById("divConteudo").style.top = "0px";
			document.getElementById("divConteudo").style.width = ((winW - 201) + "px");
			//document.getElementById("divConteudo").style.height = ((calc - 170) + "px");
			document.getElementById("divComparacao").style.height = ((calc - 205) + "px");
		} else if (pagina == "contato") {
			//document.getElementById("divCadastro").style.width = ((winW - 201) + "px");
			//document.getElementById("divCadastro").style.height = (300 + "px");
			$("#divHeader").remove();
			document.getElementById("divConteudo").style.top = "0px";
			document.getElementById("divConteudo").style.height = "100%";
			document.getElementById("divAbaixoTitulo").style.visibility = "visible";
		} else if (pagina == "updateYourBrowser") {
			document.getElementById("divConteudo").style.top = "0px";
			document.getElementById("divConteudo").style.height = "100%";
			document.getElementById("divAbaixoTitulo").style.visibility = "visible";
		}

		//alert("resize ok");
	}

	function resizeEtapas() {

	}
	
	function resizeEtapa(numEtapa) {
	
	}

	function posicaoMouse(e, divRelativo) { 
		var obj = new Object();
		var posx = 0;
		var posy = 0;
		if (!e) var e = window.event;
		if (e.pageX || e.pageY) {
			posx = e.pageX + divRelativo.scrollLeft;
			posy = e.pageY + divRelativo.scrollTop;
		} else if (e.clientX || e.clientY) {
			//alert("1divRelativo.scrollTop = " + divRelativo.scrollTop);
			posx = e.clientX;
			posy = e.clientY;
			if (isIE) {
				//alert("divRelativo.scrollTop = " + divRelativo.scrollTop);
				posx += divRelativo.scrollLeft;
				posy += divRelativo.scrollTop;
			}
		}
		obj.x = posx;
		obj.y = posy;
		return obj;
	}
	
	function iniciafadeIn(divD) {
		//alert("iniciando fade");
		divD.style.display = "block";
		fadeIn(divD.id, 0);
	}

	function posicionaDiv(divObj, tipoPosicao, e, centroParentDiv) {
		var objPos = null;
		if (e != null) {
			objPos = posicaoMouse(e, centroParentDiv);
		}	
		if (tipoPosicao == "centro") {
			divObj.style.top = objPos.y - 115 - (divObj.offsetHeight / 2);
			divObj.style.left = objPos.x - (divObj.offsetWidth / 2);
		} else if (tipoPosicao == "AcimaMouse") {
			divObj.style.top = objPos.y - 115 - divObj.offsetHeight;
			divObj.style.left = objPos.x - divObj.offsetWidth;	
		} else if (tipoPosicao == "AbaixoMouse") {
			divObj.style.top = objPos.y - 115;
			divObj.style.left = objPos.x;			
		} else if (tipoPosicao == "centroParentDiv") {
			divObj.style.top = (centroParentDiv.offsetHeight - divObj.offsetHeight) / 2;
			divObj.style.left = (centroParentDiv.offsetWidth - divObj.offsetWidth) / 2; 
		}
	}

	function posicionaDivAbsoluto(divObj, x, y) {
		divObj.style.top = objPos.y;
		divObj.style.left = objPos.x;
	}

	function fadeIn(eid, opacity) {
		//alert("opacity = " + opacity);
		var element = document.getElementById(eid);
		if (opacity < 10) {
			element.style.opacity = opacity/10;
			element.style.filter = 'alpha(opacity=' + opacity*10 + ')';
			
			var func = "fadeIn('" + eid + "', " + (opacity + 1) + ")"
			//alert(func);
			window.setTimeout(func, 33);  
		} else {
			divMenuAtivado = true;
		}
	}
	
	function inNodeSub2(node, strIdNodeProcurado, pos) {
		var result = false;
		if (strIdNodeProcurado != "") {
			//if (node.id == "divSubMenuIcone") { 
			//	alert("node.id.indexOf(strIdNodeProcurado) = " + node.id + ", " + strIdNodeProcurado + " = " + node.id.indexOf(strIdNodeProcurado));
			//}
			if (node.id && (node.id.indexOf(strIdNodeProcurado) == pos)) { 
				result = true;
			} else {
				if (node.parentNode) {
					if (node.parentNode.id && (node.parentNode.id.indexOf(strIdNodeProcurado) == pos)) {
						result = true;
					} else {
						result = inNodeSub2(node.parentNode, strIdNodeProcurado, pos);
					}
				}
			}
			//alert("inNodeSub(" + node.id + ", " + strIdNodeProcurado + ", " + pos + ") = " + result);
		}
		return result;
	}

	function inNodeSub3(node, strIdNodeProcurado, pos) {
		var result = "";
		if (strIdNodeProcurado != "") {
			if (node.id && (node.id.indexOf(strIdNodeProcurado) == pos)) { 
				result = node.id;
			} else {
				if (node.parentNode) {
					if (node.parentNode.id && (node.parentNode.id.indexOf(strIdNodeProcurado) == pos)) {
						result = node.parentNode.id;
					} else {
						result = inNodeSub3(node.parentNode, strIdNodeProcurado, pos);
					}
				}
			}
			//alert("inNodeSub(" + node.id + ", " + strIdNodeProcurado + ", " + pos + ") = " + result);
		}
		return result;
	}

	function contemOptionValue(comboObj, optionValue) {
		var result = false;
		for (var i = 0; i < comboObj.options.length; i++) {
			if (comboObj.options[i].value == optionValue) {
				result = true;
				break;
			}		
		}
		return result;
	} 

	function contemNaMatriz(matriz, valor) {
		var result = false;
		for (var i = 0; i < matriz.length; i++) {
			if (matriz[i] == valor) {
				result = true;
				break;
			}		
		}
		return result;
	} 

	function adicionaOpcao(comboObj, nomeOpcao, valorOpcao) {
		var novoOption = new Option(nomeOpcao, valorOpcao);
		//alert("novoOption.value = " + novoOption.value);
		//alert("novoOption.text = " + novoOption.text); 
		//comboObj.add(novoOption, comboObj.options.length); // IE only
		try {
			comboObj.add(novoOption, comboObj.options[comboObj.options.length - 1]); // standards compliant; doesn't work in IE
			//alert("standards");
		} catch(ex) {
			comboObj.add(novoOption, comboObj.options.length); // IE only
			//alert("iE");
		}
		//alert("fim adiciona");
	}
	
	function showDiv(divid, iframe, state) {
		var divRef = document.getElementById(divid);
		var ifrRef = document.getElementById(iframe);
		if(state) {
			//alert("showdiv.innerhtml = " + divRef.innerHTML);
			divRef.style.display = "block";
			ifrRef.style.width = divRef.offsetWidth;
			ifrRef.style.height = divRef.offsetHeight;
			//ifrRef.style.top = parseInt(divRef.style.top);
			//ifrRef.style.left = parseInt(divRef.style.left);
			ifrRef.style.left = divRef.offsetLeft;
			ifrRef.style.top = divRef.offsetTop;
			
			//ifrRef.style.zIndex = divRef.style.zIndex - 1; 
			//alert("ifrRef.style.top = " + ifrRef.style.top);
			//alert("divRef.style.top = " + divRef.style.top);
			ifrRef.style.display = "block";
		} else {
			//alert("state = false");
			divRef.style.display = "none";
			ifrRef.style.display = "none";
		}
	}

	function moveSelecionado(cbOrigem, cbDestino) {
		//alert("cbOrigem = " + cbOrigem.options.length);
		//cbOrigem.options.remove(cbOrigem.options.length - 1);
		//alert("cbOrigem = " + cbOrigem.options.length); 

		for (var i = 0; i < cbOrigem.options.length; i++) {
		 	//alert("cbOrigem.selected = " + cbOrigem.options[i].selected);
			if (cbOrigem.options[i].selected) {
				if (!contemOptionValue(cbDestino, cbOrigem.options[i].value)) {
					adicionaOpcao (cbDestino, cbOrigem.options[i].text, cbOrigem.options[i].value);
					cbOrigem.options.remove(cbOrigem.options[i].index);
					i--;
				} 
			}
		}
	}

	function escondeEtapasAssistentes(numEtapa, numAssists) {
		for (var i = 1; i <= numAssists; i++) {
			document.getElementById("etapa" + numEtapa + "assis" + i).style.display = "none";
		}
	}
	
	function fecharAssistente(numEtapa, numAssists) {
		document.getElementById("assistente").style.display = "none";
		for (var i = 1; i <= numAssists; i++) {
			document.getElementById("etapa" + numEtapa + "Assis" + i).style.display = "none";	
		}
		document.getElementById("frameBack").style.display = "none";
	}

	function abrirAssistente(numeroAssist, numEtapa, numAssistentes) {
		var winW = 630, winH = 460;
		var winW2, winW3;

		winW = parseInt(document.getElementById("divAbaixoTitulo").style.width);
		winH = parseInt(document.getElementById("divAbaixoTitulo").style.height);

		escondeEtapasAssistentes(numEtapa, numAssistentes);

		document.getElementById("assistente").style.width = winW;
		document.getElementById("assistente").style.height = winH;
		document.getElementById("assistente").style.display = "block";
		//alert("winW = " + winW);
		//alert("winH = " + winH);
		winW2 = 500;
		winH2 = 500;
		var strDivIdAnt = "";

		var strDivId = "etapa" + numEtapa + "assis" + numeroAssist;
		//alert("strDivId = " + strDivId);
		document.getElementById(strDivId).style.left = (winW - winW2) / 2;
		document.getElementById(strDivId).style.top = (winH - winH2) / 2;
		showDiv(strDivId, "frameBack", true); 
		//document.getElementById(strDivId).style.display = "block";
	}
	
	